package com.sheng.service.impl;

import com.sheng.entity.Menu;
import com.sheng.exception.MyException;
import com.sheng.mapper.MenuMapper;
import com.sheng.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sheng.util.JwtUtils;
import com.sheng.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王胜
 * @since 2022-11-21 17:16
 */
@Service
@Slf4j
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> getMenusByAccount(String token) throws MyException {
        boolean hasKey = RedisUtils.hasKey(token);
        log.info("当前token是否存在？=>" +  hasKey);
        if (hasKey){
            String account = JwtUtils.getAccount(token);
            List<Menu> menus = menuMapper.getMenusByAccount(account);
            log.info("菜单列表为：" +  menus);
            return menus;
        }
        return null;
    }
}
